package com.example.smartall.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.smartall.R;
import com.example.smartall.api.ApiConfig;
import com.example.smartall.entity.HospitalCardBean;

import java.util.List;

/**
 * @author abbas
 * @brief description
 * @date 2022-01-27
 */
public class HospitalCardListAdapter extends BaseAdapter {

    private Context context;
    private List<HospitalCardBean.RowsBean> bean;

    public HospitalCardListAdapter(Context context, List<HospitalCardBean.RowsBean> bean) {
        this.context = context;
        this.bean = bean;
    }

    @Override
    public int getCount() {
        return bean.size();
    }

    @Override
    public Object getItem(int i) {
        return bean.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (convertView == null){
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.card_item,null,false);
            viewHolder.avater = (ImageView) convertView.findViewById(R.id.avater);
            viewHolder.name = (TextView) convertView.findViewById(R.id.name);
            viewHolder.tip = (TextView) convertView.findViewById(R.id.tip);
            viewHolder.ibIn = (ImageButton) convertView.findViewById(R.id.ib_in);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        Glide.with(context).load(ApiConfig.BASE_URL + bean.get(i).getImgUrl()).into(viewHolder.avater);
        viewHolder.name.setText(bean.get(i).getName());
        if (i == 1){
            viewHolder.tip.setText("未完善");
            viewHolder.ibIn.setVisibility(View.GONE);
        }else {
            viewHolder.tip.setText("修改此就诊卡信息");
            viewHolder.ibIn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                }
            });
        }
        return convertView;
    }

    class ViewHolder{
        private ImageView avater;
        private TextView name;
        private TextView tip;
        private ImageButton ibIn;
    }
}

